import Crypto from '/src/utils/js/crypto.js';
import '/src/utils/js/hmac.js';
import '/src/utils/js/sha1.js';
import {Base64} from '/src/utils/js/base64.js';
import { userOssSignature} from '@/api/creatCenter/material';
// let data = await userOssSignature();
let date=new Date()
date=date.setHours(date.getHours() + 1)
let extime=""+new Date(date).toISOString()
var policyText = {
  "expiration": extime, //设置该Policy的失效时间，超过这个失效时间之后，就没有办法通过这个policy上传文件了
  "conditions": [
    ["content-length-range", 0, 1024*1024*100] // 设置上传文件的大小限制
  ]
};
/*var config={
  accessid:'LTAI**********************',
  accesskey:'wSs****************************Yq2f',
  osshost:'https://!*******.oss-cn-shanghai.aliyuncs.com',
  policyBase64:Base64.encode(JSON.stringify(policyText))
}*/

var config = {
  accessid: 'LTAIFe7Gph4NgHTb',
  accesskey: 'a4QzY99moj5Pd8H5G4g5fyKVyLYCXj',
  osshost: 'https://yunhunjian123.oss-cn-shanghai.aliyuncs.com',
  policyBase64: Base64.encode(JSON.stringify(policyText))
}

console.log('config',config)
//policyBase64 修改 —— config.policyBase64
var message = config.policyBase64;
var bytes = Crypto.HMAC(Crypto.SHA1, message, config.accesskey, { asBytes: true }) ;
var signature = Crypto.util.bytesToBase64(bytes);
var timetamp = new Date().getTime();
function random_string(len) {
  len = len || 32;
  var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  var maxPos = chars.length;
  var pwd = '';
  for (let i = 0; i < len; i++) {
    pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}
var OSS={
  name:'aliyun',
  host:config.osshost,
  accessid:config.accessid,
  signature:signature,
  policyBase64:config.policyBase64,
}
console.log("oss=====",OSS)
export default OSS;
